package com.ggy.babybed.socketwork.command;

import com.ggy.babybed.socketwork.NetworkConstant;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * @author gonggy
 *
 */
public class MessageCommand extends BaseCommand{
    private List<String> result = new ArrayList<>();
    private boolean run = true;

    public boolean isRun() {
        return run;
    }

    public void setRun(boolean run) {
        this.run = run;
    }

    public List<String> getResult() {
        return result;
    }

    @Override
    public boolean write(OutputStream outStream) throws IOException {
        try {
            String heart = NetworkConstant.DEFAULT_HEARTBEAT_PACKET+NetworkConstant.END_FLAG;
            outStream.write(heart.getBytes(NetworkConstant.DEFAULT_ENCODING));
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }

    }

    @Override
    public boolean read(InputStream inStream) throws IOException {
        String res = readLine(inStream);
        if(NetworkConstant.DEFAULT_HEARTBEAT_PACKET.equals(res)){
            return true;
        }
        return false;
    }

}

